/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jTFuncionario.java
 *
 * Created on 10/11/2009, 00:49:25
 */

package restaurante.forms;

import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import restaurante.dao.FuncionarioDao;
import restaurante.logica.Funcionario;

/**
 *
 * @author Fernanda
 */
public class jFCadFuncionario extends javax.swing.JFrame {

    /** Creates new form jTFuncionario */
    public jFCadFuncionario() throws SQLException {
        
        initComponents();
        populaTabela("");
        desabilitaDados();
        desabilitarVisaoTodos();
    }

    DefaultTableModel tmFuncionario = new DefaultTableModel(
            new Object [][]{
            },
            new String[]{"id", "nome","endereco","telefone","salario","data_adminissao","funcao"});
    
    private List<Funcionario> funcionarios;
    ListSelectionModel lsmFuncionario;

    public void populaTabela(String busca) throws SQLException{

        FuncionarioDao fd = new FuncionarioDao();
        funcionarios = fd.getLista("%"+busca+"%");
        
        for (Funcionario f1 : funcionarios) {
            insereTabela(f1);
        }
    }

    public void insereTabela(Funcionario f1){

        tmFuncionario.addRow(new String[]{
            String.valueOf(f1.getID()),
            f1.getNome(),
            f1.getEndereco(),
            f1.getTelefone(),
            String.valueOf(f1.getSalario()),
            f1.getData_adminissao(),
            f1.getFuncao()
        });
    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPCadFuncionario = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jBPesquisa = new javax.swing.JButton();
        jTPesquisa = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLID = new javax.swing.JLabel();
        jLNome = new javax.swing.JLabel();
        jLEndereco = new javax.swing.JLabel();
        jLTelefone = new javax.swing.JLabel();
        jLSalario = new javax.swing.JLabel();
        jLData = new javax.swing.JLabel();
        jLFuncao = new javax.swing.JLabel();
        jTID = new javax.swing.JTextField();
        jTNome = new javax.swing.JTextField();
        jTEndereco = new javax.swing.JTextField();
        jTTelefone = new javax.swing.JTextField();
        jTSalario = new javax.swing.JTextField();
        jTData = new javax.swing.JTextField();
        jTFuncao = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jBSair = new javax.swing.JButton();
        jBSalvar = new javax.swing.JButton();
        jBExcluir = new javax.swing.JButton();
        jBAlterar = new javax.swing.JButton();
        jBNovo = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTFuncionario = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setBackground(new java.awt.Color(255, 255, 255));
        setBounds(new java.awt.Rectangle(354, 124, 600, 600));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setForeground(new java.awt.Color(255, 255, 255));
        setIconImages(null);
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPCadFuncionario.setBackground(new java.awt.Color(102, 255, 204));
        jPCadFuncionario.setAlignmentX(0.0F);
        jPCadFuncionario.setAlignmentY(0.0F);
        jPCadFuncionario.setPreferredSize(new java.awt.Dimension(600, 600));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pesquisa pelo Nome do Funcionário", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(580, 61));

        jBPesquisa.setText("Pesquisa");
        jBPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBPesquisaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(124, Short.MAX_VALUE)
                .addComponent(jTPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBPesquisa)
                .addGap(24, 24, 24))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBPesquisa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do Funcionario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        jLID.setText("ID:");

        jLNome.setText("Nome:");

        jLEndereco.setText("Endereço:");

        jLTelefone.setText("Telefone:");

        jLSalario.setText("Salário:");

        jLData.setText("Data Admissão:");

        jLFuncao.setText("Função:");

        jTNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNomeActionPerformed(evt);
            }
        });

        jTEndereco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTEnderecoActionPerformed(evt);
            }
        });

        jTTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTTelefoneActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLID)
                    .addComponent(jLEndereco)
                    .addComponent(jLSalario)
                    .addComponent(jLData))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLTelefone)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTID, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLNome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTNome, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLFuncao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFuncao, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jTData, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTSalario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLID)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLNome)
                    .addComponent(jLFuncao)
                    .addComponent(jTFuncao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLEndereco)
                    .addComponent(jTEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTelefone)
                    .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLSalario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLData)
                    .addComponent(jTData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jBSair.setText("Sair");
        jBSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSairActionPerformed(evt);
            }
        });

        jBSalvar.setText("Salvar");
        jBSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalvarActionPerformed(evt);
            }
        });

        jBExcluir.setText("Excluir");
        jBExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBExcluirActionPerformed(evt);
            }
        });

        jBAlterar.setText("Alterar");
        jBAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAlterarActionPerformed(evt);
            }
        });

        jBNovo.setText("Novo");
        jBNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNovoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBAlterar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBExcluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBSalvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBSair)
                .addContainerGap(161, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBAlterar, jBExcluir, jBNovo, jBSair, jBSalvar});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jBSair)
                    .addComponent(jBSalvar)
                    .addComponent(jBExcluir)
                    .addComponent(jBAlterar)
                    .addComponent(jBNovo))
                .addContainerGap())
        );

        jTFuncionario.setModel(tmFuncionario);
        jTFuncionario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTFuncionarioMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTFuncionario);

        javax.swing.GroupLayout jPCadFuncionarioLayout = new javax.swing.GroupLayout(jPCadFuncionario);
        jPCadFuncionario.setLayout(jPCadFuncionarioLayout);
        jPCadFuncionarioLayout.setHorizontalGroup(
            jPCadFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPCadFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPCadFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPCadFuncionarioLayout.setVerticalGroup(
            jPCadFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPCadFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 271, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(jPCadFuncionario, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
        jPCadFuncionario.getAccessibleContext().setAccessibleName("CadastroFuncionario");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTNomeActionPerformed

    private void jTTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTTelefoneActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTTelefoneActionPerformed

    private void jTEnderecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTEnderecoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTEnderecoActionPerformed

    private void jBNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNovoActionPerformed
        limparCampos();
        jTID.setText("");
        habilitaDados();

    }//GEN-LAST:event_jBNovoActionPerformed

    private void jBSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalvarActionPerformed

        if (verificaDados()){
            novoCadastro();
            limparCampos();
            desabilitaDados();
        }
    }//GEN-LAST:event_jBSalvarActionPerformed

    private void jBSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSairActionPerformed
        this.dispose();
        //jTFuncionario.
        // TODO add your handling code here:
    }//GEN-LAST:event_jBSairActionPerformed

    private void jBAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAlterarActionPerformed

        if (verificaDados()){
            alteraCadastro();
            limparCampos();
            desabilitaDados();
        }
    }//GEN-LAST:event_jBAlterarActionPerformed

    private void jTFuncionarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTFuncionarioMouseClicked

        habilitaDados();
        escolherLinha();
        // TODO add your handling code here:
    }//GEN-LAST:event_jTFuncionarioMouseClicked

    private void jBExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBExcluirActionPerformed

        removerCadastro();

    }//GEN-LAST:event_jBExcluirActionPerformed

    private void jBPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBPesquisaActionPerformed
        try {
            tmFuncionario.setNumRows(0);
            populaTabela(jTPesquisa.getText());
        } catch (SQLException ex) {
            Logger.getLogger(jFCadFuncionario.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jBPesquisaActionPerformed


    public void desabilitarVisaoTodos(){

        //jPFundoCadastro.setVisible(false);
        //jPCadFuncionario.setVisible(false);

    }

    private void escolherLinha(){

        int linha = jTFuncionario.getSelectedRow();
        System.out.println(linha);

        Funcionario f1 = new Funcionario();
        String temp;

        temp = String.valueOf(jTFuncionario.getValueAt(linha, 0));
        f1.setID(Integer.parseInt(temp));
        f1.setNome(String.valueOf(jTFuncionario.getValueAt(linha,1)));
        f1.setEndereco(String.valueOf(jTFuncionario.getValueAt(linha,2)));
        f1.setTelefone(String.valueOf(jTFuncionario.getValueAt(linha,3)));
        temp = String.valueOf(jTFuncionario.getValueAt(linha, 4));
        f1.setSalario(Float.parseFloat(temp));
        f1.setData_adminissao(String.valueOf(jTFuncionario.getValueAt(linha,5)));
        f1.setFuncao(String.valueOf(jTFuncionario.getValueAt(linha,6)));

        escreverJTextField(f1);
        
    }

    private void escreverJTextField(Funcionario f1){

        System.out.println(f1);

        jTID.setEditable(true);
        jTID.setText(String.valueOf(f1.getID()));
        jTID.setEditable(false);

        jTNome.setText(f1.getNome());
        jTEndereco.setText(f1.getEndereco());
        jTTelefone.setText(f1.getTelefone());
        jTSalario.setText(String.valueOf(f1.getSalario()));
        jTData.setText(f1.getData_adminissao());
        jTFuncao.setText(f1.getFuncao());

    }
    
    private void novoCadastro(){

        Funcionario f1 = new Funcionario();
        f1.setNome(jTNome.getText());
        f1.setEndereco(jTEndereco.getText());
        f1.setTelefone(jTTelefone.getText());
        f1.setSalario(Float.parseFloat(jTSalario.getText()));
        f1.setData_adminissao(jTData.getText());
        f1.setFuncao(jTFuncao.getText());

         try {
            FuncionarioDao dao = new FuncionarioDao();
            dao.adiciona(f1);

            tmFuncionario.setNumRows(0);
            populaTabela("");

        } catch (SQLException ex) {
            Logger.getLogger(jFCadFuncionario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void alteraCadastro(){

        Funcionario f1 = new Funcionario();
        f1.setID(Integer.parseInt(jTID.getText()));
        f1.setNome(jTNome.getText());
        f1.setEndereco(jTEndereco.getText());
        f1.setTelefone(jTTelefone.getText());
        f1.setSalario(Float.parseFloat(jTSalario.getText()));
        f1.setData_adminissao(jTData.getText());
        f1.setFuncao(jTFuncao.getText());

        try {
            FuncionarioDao dao = new FuncionarioDao();
            dao.altera(f1);
            tmFuncionario.setNumRows(0);
            populaTabela("");
        } catch (SQLException ex) {
            Logger.getLogger(jFCadFuncionario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void removerCadastro(){
        
        Funcionario f1 = new Funcionario();
        f1.setID(Integer.parseInt(jTID.getText()));
        
        FuncionarioDao dao;
        try {
            dao = new FuncionarioDao();
            dao.remove(f1);
            tmFuncionario.setNumRows(0);
            populaTabela("");
        } catch (SQLException ex) {
            Logger.getLogger(jFCadFuncionario.class.getName()).log(Level.SEVERE, null, ex);
        }
        

    }

    public void limparCampos(){
        jTID.setText("");
        jTNome.setText("");
        jTEndereco.setText("");
        jTTelefone.setText("");
        jTSalario.setText("");
        jTData.setText("");
        jTFuncao.setText("");
    }

    public void desabilitaDados(){
        jTID.setEditable(false);
        jTNome.setEditable(false);
        jTEndereco.setEditable(false);
        jTSalario.setEditable(false);
        jTData.setEditable(false);
        jTTelefone.setEditable(false);
        jTFuncao.setEditable(false);
    }

    public void habilitaDados(){
        jTNome.setEditable(true);
        jTEndereco.setEditable(true);
        jTSalario.setEditable(true);
        jTData.setEditable(true);
        jTTelefone.setEditable(true);
        jTFuncao.setEditable(true);
    }

    public boolean verificaDados(){

        if (!jTNome.getText().equals("")) {
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "Campo nome ou funcao nao preenchido");
            return false;
        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAlterar;
    private javax.swing.JButton jBExcluir;
    private javax.swing.JButton jBNovo;
    private javax.swing.JButton jBPesquisa;
    private javax.swing.JButton jBSair;
    private javax.swing.JButton jBSalvar;
    private javax.swing.JLabel jLData;
    private javax.swing.JLabel jLEndereco;
    private javax.swing.JLabel jLFuncao;
    private javax.swing.JLabel jLID;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLSalario;
    private javax.swing.JLabel jLTelefone;
    private javax.swing.JPanel jPCadFuncionario;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTData;
    private javax.swing.JTextField jTEndereco;
    private javax.swing.JTextField jTFuncao;
    private javax.swing.JTable jTFuncionario;
    private javax.swing.JTextField jTID;
    private javax.swing.JTextField jTNome;
    private javax.swing.JTextField jTPesquisa;
    private javax.swing.JTextField jTSalario;
    private javax.swing.JTextField jTTelefone;
    // End of variables declaration//GEN-END:variables

}
